package cn.lingyangwl.agile.system.manager;

import cn.lingyangwl.agile.system.model.entity.RamApiResource;
import cn.lingyangwl.framework.tool.core.CollectionUtils;
import cn.lingyangwl.agile.system.mapper.RamResourceMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * @author shenguangyang
 */
@Service
public class RamResourceManager extends ServiceImpl<RamResourceMapper, RamApiResource> {


    public List<RamApiResource> listResourceByActions(Collection<String> actions) {
        if (CollectionUtils.isEmpty(actions)) {
            return Collections.emptyList();
        }
        LambdaQueryWrapper<RamApiResource> lqw = RamApiResource.lqw()
                .in(RamApiResource::getAction, actions)
                .orderByDesc(RamApiResource::getCreatedAt);
        return this.list(lqw);
    }
}
